"解决删除键失效
set backspace=2
"取消開頭的亂碼
set keyprotocol=
let &term=&term
"开启语法
syntax on
"查找结果 高亮显示
set hlsearch
"配色方案
colorscheme desert
"tab自动替换为space
"set expandtab
"tab设置为2个空格
"%ret! 2
"显示行号
set rnu
set nu
"自动缩进类型
set autoindent
"設置nerdtree
map <F2> :NERDTreeMirror<CR>
map <F2> :NERDTreeToggle<CR>
"进行版权声明的设置
"添加或更新头
map <F3> :call TitleDet()<cr>
function AddTitle()
    call append(0,"/*=============================================================================")
    call append(1,"#")
    call append(2,"# Project:")
    call append(3,"#")
    call append(4,"# Filename: ".expand("%:t"))
    call append(5,"#")
    call append(6,"# Description: ")
    call append(7,"#")
    call append(8,"# Last modified: ".strftime("%Y-%m-%d %H:%M"))
    call append(9,"#")
    call append(10,"# Designer: sgyi")
    call append(11,"#")
    call append(12,"# Email:sg_yi@outlook.com")
    call append(13,"#")
    call append(14,"=============================================================================*/")
    echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endf
"更新最近修改时间和文件名
function UpdateTitle()
    normal m'
    execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
    normal ''
    normal mk
    execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
    execute "noh"
    normal 'k
    echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
"判断前10行代码里面，是否有Last modified这个单词，
"如果没有的话，代表没有添加过作者信息，需要新添加；
"如果有的话，那么只需要更新即可
function TitleDet()
    let n=1
    "默认为添加
    while n < 10
        let line = getline(n)
        if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
            call UpdateTitle()
            return
        endif
        let n = n + 1
    endwhile
    call AddTitle()
endfunction
